package servlet;

import dao.PersonDAO;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/group/people/person_delete")
public class PersonDeleteServlet extends HttpServlet {
    public PersonDeleteServlet() {
        super();
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html; charset=UTF-8");
        String id = req.getParameter("id");
        PersonDAO dao =new PersonDAO();
        dao.deletePerson(id);
//        req.getRequestDispatcher("person_list.jsp").forward(req, resp);
        resp.setHeader("refresh", "0;URL=" + "personList");
    }
}
